const BASE_URL_DEV = "http://localhost:8721/api/"
const BASE_URL_PROD = "https://aiauth.breez.work/api/"
const app = getApp();
function showToast(title, icon, duration) {
  wx.showToast({
    title: title,
    icon: icon,
    duration: duration
  })
}
function showLoading(title) {
  wx.showLoading({
    title: title,
    mask: true
  })
}
function hideLoading() {
  setTimeout(function () {
    wx.hideLoading()
  }, 300)
}

function request(url, data = {}, method = "GET") {
  return new Promise(function (resolve, reject) {
    wx.request({
      url: BASE_URL_PROD + url,
      data: data,
      // header: {
      //   Authorization: wx.getStorageSync('token')
      // },
      method: method,
      success: function (res) {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res.errMsg)
        }
      },
      fail: function (err) {
        reject(err)
      }
    })
  });
}

module.exports = {
  request, showToast, showLoading, hideLoading
}